package com.dudu.util;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by xujingshi on 16/9/2.
 */
public class ValidateUtil {

    public static Boolean validateTelephone(String telephone){
        return telephone.matches("1[345789]\\d{9}");
    }

    /**
     * 身份证号校验
     * @param idCard
     * @return
     */
    public static Boolean validateIdCard(String idCard){
        return idCard.matches("(^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$)" +
                "|(^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])((\\d{4})|\\d{3}[Xx])$)");
    }

    /**
     * 验证payer为1时payername是否不为空
     * @param payer
     * @param payerName
     * @return
     */
    public static Boolean validatePayer(int payer, String payerName){
        if(1 == payer){
            if(null == payerName || 0 == payerName.trim().length()){
                return false;
            }
        }
        return true;
    }

    public static Boolean matches(String target, List<String> params){
        StringBuffer condition = new StringBuffer();
        for(String param : params){
            condition.append(".*?").append(param).append(".*?|");
        }
        return target.matches(condition.substring(0, condition.length()-1));
    }



}
